import request from '@/config/axios'

export interface DeliveryPickUpStoreVO {
  id: number
  name: string
  introduction: string
  phone: string
  areaId: number
  detailAddress: string
  logo: string
  openingTime: string
  closingTime: string
  latitude: number
  longitude: number
  status: number
  verifyUserIds: number[] // 绑定用户编号组数
  // --- 门店账户设置 ---
  storeMgAcct?: string // 管理员账号 - 创建时需要，更新时可能不需要
  storeMgPw?: string // 管理员密码 - 创建时需要，更新时可能不需要
  storeMgAvatar?: string // 管理员头像
  storeMgPhone?: string // 管理员手机号
  isChainStore?: boolean // 是否连锁店
  verifyUsers?: number[] // 核销人员ID列表
  // --- 门店营业设置 ---
  operatingStatus?: number // 营业状态: 0-营业中, 1-休息中, 2-已关闭
  deliveryExpress?: boolean
  deliverySelfPickup?: boolean
  deliveryStore?: boolean
  deliveryPickupPoint?: boolean
  notifierUserIds?: number[] // 通知人ID列表
  h5RedirectUrl?: string // H5支付跳转
  mpRedirectUrl?: string // 小程序支付跳转
  homepageDisplayOptions?: string[] // 首页显示: 'consultation', 'shopInStore'
  companyTotalTimes?: number // 当前AI舌诊次数剩余次数（只读）
  aiTongueTimes?: number // 门店AI舌诊次数（可编辑）
  // --- 门店详情 ---
  details?: string // 富文本详情
  // --- 其他设置 ---
  expressQueryTarget?: string // 'sender' or 'receiver'
  senderMobile?: string
  // --- 以下字段可能来自响应，但提交时不需要或由后端生成 ---
  // categoryId?: number
  // businessLicense?: string
  wxaQrcode?: string // Add this field to hold the QR code URL
  // idCardFront?: string
  // idCardBack?: string
  // storePhotosOther?: string
  // storeBanner?: string
  // storeAdvertisement?: string
  // expireTime?: string
  // joinStatus?: number
  // createTime?: string
}

// 查询自提门店列表
export const getDeliveryPickUpStorePage = async (params: any) => {
  return await request.get({ url: '/trade/delivery/pick-up-store/page', params })
}

// 查询自提门店详情
export const getDeliveryPickUpStore = async (id: number) => {
  return await request.get({ url: '/trade/delivery/pick-up-store/get?id=' + id })
}

// 查询自提门店精简列表
export const getSimpleDeliveryPickUpStoreList = async (): Promise<DeliveryPickUpStoreVO[]> => {
  return await request.get({ url: '/trade/delivery/pick-up-store/simple-list' })
}

// 新增自提门店
export const createDeliveryPickUpStore = async (data: DeliveryPickUpStoreVO) => {
  return await request.post({ url: '/trade/delivery/pick-up-store/create', data })
}

// 修改自提门店
export const updateDeliveryPickUpStore = async (data: DeliveryPickUpStoreVO) => {
  return await request.put({ url: '/trade/delivery/pick-up-store/update', data })
}

// 删除自提门店
export const deleteDeliveryPickUpStore = async (id: number) => {
  return await request.delete({ url: '/trade/delivery/pick-up-store/delete?id=' + id })
}

// 绑定自提店员
export const bindStoreStaffId = async (data: any) => {
  return await request.post({ url: '/trade/delivery/pick-up-store/bind', data })
}
// 查询自提门店库存记录
export const getSingleItemStockRecord = async (params: any) => {
  return await request.get({ url: '/trade/single-item-stock-record/record', params })
}

// 门店佣金记录
export const storeCommissionRecord = (params) => {
  return request.get({ url: '/trade/store-commission-record/page', params })
}
// 门店预备会员
export const storeMemberUserPendingBiz = (params) => {
  return request.get({ url: '/member/user-pending-biz/page', params })
}

// 获得自提门店列表 (可能某些选择器需要)
// export const getDeliveryPickUpStoreList = (params) => {
//   return request.get({ url: '/trade/delivery/pick-up-store/list', params })
// }

// 生成门店小程序码
export interface StoreWxQrReqVO {
  id: number
  scene: string
  path: string
  width: number
  autoColor: boolean
  checkPath: boolean
  hyaline: boolean
}

export const generateStoreWxaQrCode = (data: StoreWxQrReqVO) => {
  return request.post<string>({ url: '/trade/delivery/pick-up-store/gen-wxa-qrcode', data })
}
